<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <input type="text" id="txt">
    <span id="content"></span>
    <button id="btn">btn</button>
    <script>
        //邮箱的规则 一串数字，字母或下划线@一串数字英文，一串英文
        var reg=/^\w+@\w+\.[a-z]+$/;
        var txt=document.getElementById("txt");
        var content=document.getElementById("content");
        var btn=document.getElementById("btn");
        btn.onclick=function(){
            var value=txt.value;
            var result=reg.test(value);
        if(result){
            content.innerHTML="邮箱正确";
            content.style.color="green";
        }else{
            content.innerHTML="邮箱格式不合法";
            content.style.color="red";
        }
        }
    </script>
</body>
</html>